 import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
 
public class wektor extends JApplet implements MouseListener, MouseMotionListener
{
   int x = 0;
   int y = 0;
   int[] tabx = new int[2];
   int[] taby = new int[2];
   int[] pierwiastki;
   int i,ii,j,k = 0;
   int a,b,c,delta,p,q = 0;
 
   public void init()
   { 
        JRootPane rootPane = this.getRootPane();    
        rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
        
        addMouseListener(this);             //Inicjalizacja obslugi myszy
        addMouseMotionListener(this);       //Inicjalizacja obsl myszy - przesuwanie...
   }
   
    //----------------------funkcja rysujaca------------------------------
   public void paint(Graphics g)
    {
        g.setColor(Color.black);
        g.drawRect(0, 0, 500, 500);             //ramka
        g.setColor(Color.black);                
        g.drawLine(0,250,500,250);              //os x
        g.drawLine(493, 247, 500, 250);  //strzeleczka
        g.drawLine(493, 253, 500, 250);  //
        g.drawLine(250,0,250,500);              //os y
        g.drawLine(247, 5, 250, 0);      // strzaleczka
        g.drawLine(253, 5, 250, 0);
        //-------rysowanie podzialki na osiach-----------
        while(i<500)
        {
           i+=10;
           g.drawLine(i,245,i,255); 
           g.drawLine(245,i,255,i);
           if (i>240)
           {
           String s = Integer.toString((i-250)/10);
           g.drawString(s, i, 240);
        }
           //else if(i
        }
        getGraphics().fillOval(x,y,2,2);
        if(y==250 && ii<2)
        {
           tabx[ii]=(x-250)/10;
           ii++;
        }
        if(ii==2)
        {
        a=25/(tabx[1]-tabx[0]);
        b=-(tabx[1]*tabx[0])*a;
        c=(tabx[0]+tabx[1])*a;
        g.drawString("Wzor funckji wynosi: y = "+a+"x^2 + "+b+"x + "+c,10,40);
        g.drawString( wiezcholek(a, b, c) ,10,50);
        }
    }
    public String wiezcholek(int a,int b, int c)
    {
        int x=-b/2*a;
        int y=(b*b-2*a*c)/4*a;
      //g.drawString("Wspolzedne wiezcholka to: ("+x+","+y+") ",10,50); 
      return "Wspolzedne wiezcholka to: ("+x+","+y+") ";
    }
    //---------------------------------------------------------------------
    public void mousePressed  (MouseEvent evt)
    {
    }
    //-----------------------------------------------------------------------
    
    //-----------------------------------------------------------------------
    public void mouseExited   (MouseEvent evt)
    {
    }
    
   //-----------------------------------------------------------------------
    
    //-----------------------------------------------------------------------
    public void mouseEntered  (MouseEvent evt)
    {
    }
    //-----------------------------------------------------------------------
    
    //-----------------------------------------------------------------------
    public void mouseReleased (MouseEvent evt)
    {
    }
    //-----------------------------------------------------------------------
    
    //------------------------Obsluga kliknecia myszka-----------------------
    public void mouseClicked  (MouseEvent evt)
    {
        //x=evt.getX();               //Pobranie pozycji x klikniecia
        //y=evt.getY();               //Pobranie pozycji y klikniecia
        //repaint();                  //Ponowne wykonanie metody paint
    }
    //-----------------------------------------------------------------------
    
    //---------Obsluga przesuwania myszy z wcisnietym przyciskiem------------
    public void mouseDragged(MouseEvent evt)
    {
       
        x = evt.getX();               //Pobranie pozycji x
        y = evt.getY();               //Pobranie pozycji y
        
        repaint();                  //Ponowne wykonanie metody paint
    }
    //-----------------------------------------------------------------------
    
    //---------Obsluga przesuwania myszy bez wcisnietego przycisku-----------
    public void mouseMoved(MouseEvent evt)
    {
    }
    
   //-----------------------------------------------------------------------
}